package model.qna;

import java.sql.SQLException;

import java.util.List;

import model.letter.ListVO;


public class QnABoardService {
	private QnABoardDao dao;
	
	public QnABoardService(){}

	public QnABoardService(QnABoardDao dao) {
		super();
		this.dao = dao;
	}

	public void qnaWrite(QnABoardVO qbvo) throws SQLException {
		int no=(Integer)dao.qnaWrite(qbvo);
		qbvo.setQnaNo(no);
		
		
	}



	public void qnaDelete(int qnaNo) throws SQLException {
		dao.qnaDelete(qnaNo);
	}

	public QnAListVO qnaListView(String pageNo) throws SQLException {
		QnAListVO listVO = new QnAListVO();
		System.out.println("서비스 페이지 : "+ pageNo);
		int nowPage = 0;
		if(pageNo==null){
			pageNo = "1";
			nowPage =  Integer.parseInt(pageNo);
			 
		}else{
			nowPage= Integer.parseInt(pageNo);
		}
		int totalContents = dao.getTotalContents();
		QnAPaggingBean bean = new QnAPaggingBean(nowPage, totalContents);
		listVO.setPagingBean(bean);
		List<QnABoardVO> list = dao.qnaListView(nowPage);
		listVO.setList(list);
		return listVO;
	}

	public QnABoardVO qnaUpdateGetContent(int qnaNo) throws SQLException {
		
		return dao.qnaUpdateGetContent(qnaNo);
	}

	public void qnaUpdate(QnABoardVO qnaVO) throws SQLException {
		
		dao.qnaUpdate(qnaVO);
		
	}

	public boolean qnaCheckPassword(QnABoardVO qnaVO) throws SQLException {
		boolean flag = true;
		String qnaPassword = dao.qnaCheckPassword(qnaVO);
		if(qnaPassword==null){
			flag = false;
		}
		
		return flag;
	}

	public QnABoardVO qnaGetContent(int qnaNo) throws SQLException {
		dao.updateqnaCount(qnaNo);
		return dao.qnaUpdateGetContent(qnaNo);
	}

	public int qnaGetMaxQnaRestep(int qnaRef) throws SQLException {
		// TODO Auto-generated method stub
		return dao.qnaGetMaxQnaRestep(qnaRef);
	}



	public void qnaReWrite(QnABoardVO vo) throws SQLException {
		// TODO Auto-generated method stub
		int qnaRestep = vo.getQnaRestep();
		int qnaRelevel = vo.getQnaRelevel();
		vo.setQnaRestep(qnaRestep+1);
		vo.setQnaRelevel(qnaRelevel+1);
		System.out.println(vo);
		int no = dao.qnaReWrite(vo);
		vo.setQnaNo(no);
	}



}
